<?php

namespace app\common\model;

use basic\ModelBasic;

use service\AliMessageService;

class SmsCode extends ModelBasic
{
	use \traits\ModelTrait;

	/**
	 * 使用验证码
	 * @param  [type] $mobile [description]
	 * @param  [type] $code   [description]
	 * @return [type]         [description]
	 */
	public static function valid_sms_code($mobile , $code)
	{
		$sms_record = self::field('code,is_use')->where(['tel' => $mobile , 'is_use' => 0])->where('last_time' , 'gt' , time())->find();

		if ( empty($sms_record) ) return false;

		if ( $code != $sms_record->code ) return false;

		$sms_record->is_use = 1;
		return $sms_record->save();
	}
}//Class End
